package com.rzz.stack_queue;

import java.util.Stack;

/**
 * @description: 实现一个特殊的栈，在实现栈的基础功能时，能够返回栈中最小元素,pop,push,getMin
 * @author: ruanzhizhi
 * @date: 2021/6/6 18:13
 */
public class GetMinStack {
    public static void main(String[] args) {
        Satck1 satck1 = new Satck1();
        satck1.push(4);
        satck1.push(5);
        satck1.push(8);
        satck1.push(3);
        satck1.push(2);
        satck1.push(6);
        satck1.pop();
        satck1.pop();
        satck1.pop();
        System.out.println("min:"+satck1.getMin());
    }

}

class Satck1{
    public Stack<Integer> stackData = new Stack<>();
    public Stack<Integer> stackMin = new Stack<>();

    public void pop(){
        if (stackData==null || stackData.size()==0){
            System.out.println("空栈");
            return;
        }
        Integer pop = stackData.pop();
        System.out.println("pop:"+pop);
        stackMin.pop();
    }

    public void push(Integer num){
        stackData.push(num);
        if (stackMin==null || stackMin.size()==0){
            stackMin.push(num);
        }else {
            if (num<stackMin.peek()){
                stackMin.push(num);
            }else {
                stackMin.push(stackMin.peek());
            }
        }
    }

    public Integer getMin(){
        if (stackMin==null || stackMin.size()==0){
            System.out.println("空栈");
            return Integer.MIN_VALUE;
        }
        return stackMin.peek();
    }

}

class Satck2{

}
